package InheritanceAndPolymorphism.demo04;

public class Auto {
    /**
     * 建立一个汽车Auto类，包括轮胎个数，汽车颜色，车身重量、速度等成员变量。
     * 并通过不同的构造方法创建实例。至少要求： 汽车能够加速，减速，停车。
     */
    private int tireCount;
    private String color;
    private double weight;
    private double speed;

    public Auto(int tireCount, String color, double weight) {
        this.tireCount = tireCount;
        this.color = color;
        this.weight = weight;
        this.speed = 0;
    }

    public void accelerate(double increment) {
        this.speed += increment;
        System.out.println("汽车加速，当前速度: " + this.speed);
    }

    public void decelerate(double decrement) {
        if (this.speed - decrement < 0) {
            this.speed = 0;
        } else {
            this.speed -= decrement;
        }
        System.out.println("汽车减速，当前速度: " + this.speed);
    }

    public void stop() {
        this.speed = 0;
        System.out.println("汽车停车，当前速度: 0");
    }

}
